const {TOKEN} = require('../tools/constant')

// 存储
exports.setItem = (key, value) => {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  return wx.setStorageSync(key, value)
}

// 取出本地缓存的值
exports.getItem = key =>{
  const data = wx.getStorageSync(key)
  try {
    return JSON.parse(data)
  } catch (error) {
    return data
  }
}

// token存取，为了编码更方便
exports.setToken = value => wx.setStorageSync(key, value)
exports.setToken = () => wx.getStorageSync(TOKEN)

